<template>
  <div class="margin-top-20">
    <el-form ref="form" :model="form" label-width="160px">
      <el-form-item label="站点名称">
        <el-input v-model="form['siteTitle']"/>
      </el-form-item>
      <el-form-item label="页面title">
        <el-input v-model="form['seoTitle']"/>
      </el-form-item>
    </el-form>
    <div style="text-align: center;">
      <el-button type="primary" size="small" @click="onSubmit">保 存</el-button>
    </div>
  </div>
</template>

<script>
  export default {
    props: {
      form: {
        type: Object,
        default: function() {
          return {
            // 站点名称
            siteTitle: '',
            // 页面标题
            seoTitle: ''
          }
        }
      }
    },
    data() {
      return {}
    },
    mounted(){
      // this.loadData();
    },
    methods: {
      // 加载数据
      loadData(){
        (async () => {
          const result = await this.$service.adminSystemGetSystemConfig();
          if (result.code === 0) {
            this.form = result.data;
          }
        })();
      },
      // 提交
      onSubmit() {
        this.$refs.form.validate(valid => {
          if (valid) {
            (async () => {
              const params = Object.assign({}, this.form);
              const result = await this.$service.adminSystemUpdateSystemConfig(params);
              if (result.code === 0) {
                this.$message.success('操作成功~');
                this.loadData();
              } else {
                this.$message.error(result.msg);
              }
            })();
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      }
    }
  }
</script>
